import java.util.Scanner;

interface IsBadVersion {
    //判断是不是错误版本
    public void isCorrectVersion();
}

class Work {
    //判断是不是错误版本
    public boolean isCorrectVersion(int mid) {
       return true;
    }
}

class HomeWork extends Work{

    //搜索插入位置
    public int searchInsert(int[] nums, int target) {
        int n = nums.length;
        int left = 0; //从数组最左边开始
        int right = n - 1; //从数组最右边开始
        int ans = n; //记录下标
        while (left <= right) {
            int mid = ((right - left) >> 1) + left; //中间位置
            if (target <= nums[mid]) { //要找的数小于或者等于mid说明要找的数在左边
                ans = mid;
                right = mid - 1;
            } else { //要找的数大于mid说明要找的数在右边
                left = mid + 1;
            }
        }
        return ans;
    }

    //第一个错误的版本
    public int firstBadVersion(int n) {
        int left = 1; //左边界
        int right = n; //右边界
        while (left < right) {
            //求中间版本的位置
            int mid = left + (right - left) / 2;
            if (isCorrectVersion(mid)) {
                //如果是错误版本
                right = mid;
            } else {
                //如果不是
                left = mid + 1;
            }
        }
        //return left;
        //或者
        return right;
    }
}

public class HomeWorkDay6 {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        int n = 5;
        int[] nums = new int[n];
        System.out.println("输入数组元素：");
        for (int i = 0; i < nums.length; i++) {
            //输入数组的元素
            nums[i] = input.nextInt();
        }

        // 输入要查找的数字
        int target = input.nextInt();

        System.out.println("输入几个版本：");
        int num = input.nextInt();

        System.out.println("输入错误版本：");
        int bad = input.nextInt();

        HomeWork homeWork = new HomeWork();

        System.out.println(homeWork.searchInsert(nums, target));

        System.out.println("错误版本：" + homeWork.firstBadVersion(target));
    }
}
